﻿Imports BE.BE
Imports DAL.DAL

Namespace BL
    Public Class Expediente_BL

        Shared Sub guardar(pExpediente As Expediente_BE)

            Try
                DAL_Expediente.guardar(pExpediente)

                If Not IsNothing(pExpediente.Notas) Then
                    If pExpediente.Notas.Count > 0 Then

                        For Each nota As Nota_BE In pExpediente.Notas

                            Nota_BL.guardar(nota, pExpediente.IdExpediente)

                        Next

                    End If
                End If
                
            
            Catch ex As Exception
                Throw ex
            End Try




        End Sub

        Shared Sub modificar(pExpediente As Expediente_BE)

            Try
                DAL_Expediente.modificar(pExpediente)

                If pExpediente.Notas.Count > 0 Then

                    Nota_BL.borrar(pExpediente.IdExpediente)

                    For Each nota As Nota_BE In pExpediente.Notas

                        Nota_BL.guardar(nota, pExpediente.IdExpediente)

                    Next

                End If

            Catch ex As Exception
                Throw ex
            End Try


        End Sub

        Shared Function obtener(pId As Integer) As Expediente_BE
            Return Nothing
        End Function

        Shared Function listarExpediente() As List(Of Expediente_BE)
            Dim mlista As New List(Of Expediente_BE)

            Try
                mlista = DAL_Expediente.listarExpediente()

                If mlista.Count > 0 Then
                    For Each expe As Expediente_BE In mlista

                        expe.Notas = Nota_BL.obtenerXExpedente(expe.IdExpediente)

                    Next


                End If

                Return mlista
            Catch ex As Exception
                Throw ex
            End Try

        End Function

    End Class
End Namespace

